package com.example.myapplication;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

  ViewPager viewPager;
  TabLayout tabLayout;

  String userAccount;
  String userName;

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    SetUserInfo();
    Init();
  }

  private void SetUserInfo() {
    userAccount = getIntent().getStringExtra("userAccount");
    userName = getIntent().getStringExtra("userName");
  }

  private void Init() {
    viewPager = findViewById(R.id.viewPager);
    tabLayout = findViewById(R.id.tabLayout);
    //创建Fragment列表
    ArrayList<Fragment> fragments = new ArrayList<>();

    Bundle userBundle = new Bundle();
    userBundle.putString("userAccount", userAccount);
    userBundle.putString("userName", userName);

    NoteViewFragment noteFragment = new NoteViewFragment();

    noteFragment.setArguments(userBundle);

    fragments.add(noteFragment);

    UserInfoFragment userInfoFragment = new UserInfoFragment();
    userInfoFragment.setArguments(userBundle);

    fragments.add(userInfoFragment);
    //创建FragmentStatePagerAdapter 并设置为ViewPager的适配器
    FragmentStatePagerAdapter pagerAdapter =
        new FragmentStatePagerAdapter(this, getSupportFragmentManager(), fragments);
    viewPager.setAdapter(pagerAdapter);
    //将ViewPager与TabLayout关联
    tabLayout.setupWithViewPager(viewPager);


    //设置样式


  }
}
